package com.qymerge.manage.core.bean;

import lombok.Data;

/**
 * Desc 分页组件
 * User cong.li
 * Date 2017/4/4
 * Time 22:25
 */
@Data
public class PageRequest {

    private static final int MAX_SIZE = 200;
    private int page = 1;
    private int size = 20;
    private String order;   //排序条件(field1:asc,field2:desc)

    public int getSkip() {
        return (page - 1) * size;
    }

    public PageRequest() {
    }

    public PageRequest(int page, int size) {
        this.page = page;
        this.size = size;
    }

    public PageRequest(int page, int size, String order) {
        this.page = page;
        this.size = size;
        this.order = order;
    }

    public PageRequest(ParamCommon common) {
        if (common != null) {
            this.page = common.getPage();
            this.size = common.getSize();
            if(common.getOrder()!=null){
                this.order = common.getOrder();
            }
        }
    }

    public PageRequest(ParamCommon common, String order) {
        if (common != null) {
            this.page = common.getPage() < 1 ? 1 : common.getPage();
            this.size = common.getSize() < 1 ? MAX_SIZE : common.getSize();
        }
        if (order != null) {
            this.order = order;
        }
    }
}
